#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#   mail: infaaf@126.com


from django import  template

from django.utils.safestring import  mark_safe
register=template.Library()



@register.simple_tag
def render_app_name(admin_class):
    return admin_class.model._meta.verbose_name_plural


@register.simple_tag
def get_query_sets(admin_class):
    return admin_class.model.objects.all()


@register.simple_tag
def render_row_obj(row_obj,admin_class):
    row_ele=''
    for col in admin_class.list_display:
        print(row_obj.qq)
        print("col: %s"%col)

        if row_obj._meta.get_field(col).choices:
            col_data=getattr(row_obj,'get_%s_display'%col)()
        else:
            col_data=getattr(row_obj,col)
        print(col_data)

        row_ele+='<td>%s</td>'%col_data
    return mark_safe(row_ele)

